/*
 * @Author: llch
 * @Date: 2020-06-18 09:50:16
 * @LastEditTime: 2020-06-19 15:09:08
 * @LastEditors: Please set LastEditors
 * @Description: 人物换装组件
 * @FilePath: \man_demo\assets\Script\Player\Player.ts
 */ 

const {ccclass, property} = cc._decorator;

@ccclass
export class Player extends cc.Component {
    /* =========wing============ */
    @property(cc.Node)
    public wing: cc.Node = null;

    /* ========head============= */
    @property(cc.Node)
    public head: cc.Node = null;
    @property(cc.Node)
    public blusher: cc.Node = null;
    @property(cc.Node)
    public eye: cc.Node = null;
    @property(cc.Node)
    public eyebrow: cc.Node = null;
    @property(cc.Node)
    public hair: cc.Node = null;
    @property(cc.Node)
    public hair_skin: cc.Node = null;
    @property(cc.Node)
    public mouse: cc.Node = null;

    /* ========body============ */
    @property(cc.Node)
    public body: cc.Node = null;
    @property(cc.Node)
    public shoes: cc.Node = null;
    @property(cc.Node)
    public bottom_clothes: cc.Node = null;
    @property(cc.Node)
    public top_clothes: cc.Node = null;

    @property(cc.Node)
    public coat: cc.Node = null;
    @property(cc.Node)
    public coat_skin: cc.Node = null;
    @property(cc.Node)
    public wholebodyclothes: cc.Node = null;
    @property(cc.Node)
    public wholebodyclothes_skin: cc.Node = null;
    @property(cc.Node)
    public christmasclothes: cc.Node = null;
    @property(cc.Node)
    public christmasclothes_skin: cc.Node = null;
    @property(cc.Node)
    public bag: cc.Node = null;

    public color: cc.Color;     // 保存人物颜色

    /* ========accessory============ */
    @property(cc.Node)
    public accessory: cc.Node = null;

    /* ========bg============ */
    @property(cc.Node)
    public bgSprite: cc.Node = null;
    
    // 换肤
    public changePlayerColor(color: cc.Color) {
        this.head.color = color;
        this.body.color = color;
        this.color = color;
    }

    // wing
    public changeWing(sf: cc.SpriteFrame) {
        this.wing.getComponent(cc.Sprite).spriteFrame = sf;
    }    
    // blusher
    public changeBlusher(sf: cc.SpriteFrame) {
        this.blusher.getComponent(cc.Sprite).spriteFrame = sf;
    }
    // eye
    public changeEye(sf: cc.SpriteFrame) {
        this.eye.getComponent(cc.Sprite).spriteFrame = sf;
    }
    // eyebrow
    public changeEyebrow(sf: cc.SpriteFrame) {
        this.eyebrow.getComponent(cc.Sprite).spriteFrame = sf;
    }
    // hair
    public changeHair(sf: cc.SpriteFrame, skin: cc.SpriteFrame) {
        this.hair.getComponent(cc.Sprite).spriteFrame = sf;
        this.hair_skin.getComponent(cc.Sprite).spriteFrame = skin;
    }
    // mouse
    public changeMouse(sf: cc.SpriteFrame) {
        this.mouse.getComponent(cc.Sprite).spriteFrame = sf;
    }
    // shoes
    public changeShoes(sf: cc.SpriteFrame) {
        this.shoes.getComponent(cc.Sprite).spriteFrame = sf;
    }
    // bottom_clothes
    public changeBottomClothes(sf: cc.SpriteFrame) {
        this.bottom_clothes.getComponent(cc.Sprite).spriteFrame = sf;
    }
    // top_clothes
    public changeTopClothes(sf: cc.SpriteFrame) {
        this.top_clothes.getComponent(cc.Sprite).spriteFrame = sf;
    }

    // coat
    public changeCoat(sf: cc.SpriteFrame, skin: cc.SpriteFrame, v2: cc.Vec2) {
        this.coat.getComponent(cc.Sprite).spriteFrame = sf;
        this.coat_skin.getComponent(cc.Sprite).spriteFrame = skin;
        this.coat_skin.color = this.color;
        this.coat.setPosition(v2);

    }
    // wholebodyclothes
    public changeWholebodyclothes(sf: cc.SpriteFrame, skin: cc.SpriteFrame, flag: boolean) {
        this.wholebodyclothes.getComponent(cc.Sprite).spriteFrame = sf;
        this.wholebodyclothes_skin.getComponent(cc.Sprite).spriteFrame = skin;
        this.wholebodyclothes_skin.color = this.color;
        
        if (flag) {
            this.wholebodyclothes.active = false;
            // 显示 上衣 裤子 外套
            this.show();
        } else {
            this.wholebodyclothes.active = true;
            // 隐藏 上衣 裤子 外套
            this.hide()
        }
        this.christmasclothes.active = false;
    }

    // christmasclothes
    public changeChristmasclothes(sf: cc.SpriteFrame, skin: cc.SpriteFrame, flag: boolean) {
        this.christmasclothes.getComponent(cc.Sprite).spriteFrame = sf;
        this.christmasclothes_skin.getComponent(cc.Sprite).spriteFrame = skin;
        this.christmasclothes_skin.color = this.color;

        if (flag) { // 为真说明需要隐藏
            this.christmasclothes.active = false;
            // 显示 上衣 裤子 外套
            this.show();
        } else {
            this.christmasclothes.active = true;
            // 隐藏 上衣 裤子 外套
            this.hide();
        }
        this.wholebodyclothes.active = false;
    }

    // bag
    public changeBag(sf: cc.SpriteFrame) {
        this.bag.getComponent(cc.Sprite).spriteFrame = sf;
    }
    // accessory
    public changeAccessory(sf: cc.SpriteFrame) {
        this.accessory.getComponent(cc.Sprite).spriteFrame = sf;
    }

    // 发型变色
    public changeHairColor(color: cc.Color) {
        this.hair.color = color;
        this.hair_skin.color = color;
    }

    // 显示 上衣 裤子 外套
    public show() {
        this.coat.active = true;
        this.top_clothes.active = true;
        this.bottom_clothes.active = true;
    }
    
    // 隐藏 上衣 裤子 外套
    public hide() {
        this.coat.active = false;
        this.top_clothes.active = false;
        this.bottom_clothes.active = false;
    }

    // bg
    public changeBg(sf: cc.SpriteFrame) {
        this.bgSprite.getComponent(cc.Sprite).spriteFrame = sf;
    }
}